<template>
  <div class="content-wrapper">
    <div class="content-container">
      <div class="filter-container" />
      <el-form :inline="true" ref="form" :model="listQuery" label-width="80px">
        <el-form-item label="知识库名称">
          <el-input
            class="filter-item"
            v-model="listQuery.repositoryName"
          ></el-input>
        </el-form-item>
        <el-button
          v-waves
          class="filter-item"
          size="small"
          round
          type="primary"
          icon="el-icon-search"
          @click="getList"
          >搜索</el-button
        >
      </el-form>
      <div>
        <el-table
          height="500"
          v-loading="listLoading"
          :data="list"
          highlight-current-row
          style="width: 100%"
        >
          <el-table-column label="名称" min-width="200">
            <template slot-scope="{ row }">
              <span>
                <svg class="icon" aria-hidden="true">
                  <use xlink:href="#el-icon-allzhishiku"></use>
                </svg>
                <router-link
                  :to="{
                    path: '/document/repository_file/' + row.repositoryId,
                    query: {
                      repositoryName: row.repositoryName,
                      row: row,
                    }
                  }"
                  >{{ row.repositoryName }}</router-link
                >
              </span>
            </template>
          </el-table-column>
          <el-table-column prop="size" label="大小"> </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="150px"
            fixed="right"
          >
            <template slot-scope="{ row }">
              <el-dropdown trigger="click" class="filter-item">
                <el-button type="text"><i class="el-icon-more" /></el-button>
                <el-dropdown-menu slot="dropdown" class="user-dropdown">
                  <el-dropdown-item @click.native="detail(row.repositoryId)"
                    >设置</el-dropdown-item
                  >
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--      <pagination-->
      <!--        v-show="total > 0"-->
      <!--        :total="total"-->
      <!--        :page-number.sync="listQuery.pageNumber"-->
      <!--        :page-size.sync="listQuery.pageSize"-->
      <!--        @pagination="getList"-->
      <!--      />-->
    </div>
  </div>
</template>

<script>
import { pageRepository } from '@/api/fd/repository'
import Pagination from '@/components/Pagination'
import { mapGetters } from 'vuex'
import { isTeamAdmin } from '@/api/uc/team.js'
import { set, get } from '@/utils/db.js'
import waves from '@/directive/waves' // waves directive

export default {
  components: { File, Pagination },
  directives: { waves },
  data() {
    return {
      total: 0,
      multipleSelection: [],
      list: null,
      listLoading: true,
      listQuery: {
        isTeamAdmin: null, //是否为团队管理员
        belongType: null,
        belongTo: null,
        pageNumber: 1,
        pageIndex: 0,
        pageSize: 10,
        repositoryName: null
      },
      apply: '',
      router: this.$router.history.current.path
    }
  },
  computed: {
    ...mapGetters(['userId'])
  },
  mounted() {
    this.isTeamAdmin(this.$route.params.userGroupId)
  },
  methods: {
    // 获取是否为管理员
    async isTeamAdmin(id) {
      let data = await isTeamAdmin({
        teamId: id
      })
      this.apply = data.data
      set('TeamAdmin', this.apply)
      this.getList()
    },
    detail(id) {
      this.$router.push({
        path: '/document/setting/' + id,
        query: { id: this.$route.params.userGroupId }
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    getList() {
      if (this.$route.params.userGroupId) {
        this.listQuery.belongType = 1
        this.listQuery.belongTo = this.$route.params.userGroupId
      } else {
        this.listQuery.belongType = 0
        this.listQuery.belongTo = this.userId
      }
      this.listQuery.pageIndex = this.listQuery.pageNumber - 1
      this.listQuery.isTeamAdmin = get('TeamAdmin') == 'true' ? 1 : 0
      pageRepository(this.listQuery).then((res) => {
        if (res.code === 1) {
          this.list = res.data.rows
          this.total = res.data.total
        }
        this.listLoading = false
      })
    },
    openRepository(item) {
      console.log(item, '知识库')
    }
  }
}
</script>
